package com.mjlf.mjatis.sql;

import lombok.Data;

import java.util.List;
import java.util.Objects;

/**
 * @ClassName SqlBound
 * @Author mjlft
 * @Date 2020/6/12 22:27
 * @Version 1.0
 * @Description mapper sql 解析后与 参数注册的对象， 应为传入的参数可能与mapper sql不能对应上
 * 这里需要做绑定解析
 */
@Data
public class SqlBound {

    //解析以后的sql 如: insert into test(id, name) values(?, ?);
    private String sql;
    //解析出来的参数， 应该与解析出来的sql一一对应上
    private List<Object> params;

    public SqlBound() {
    }

    public SqlBound(String sql, List<Object> params) {
        this.sql = sql;
        this.params = params;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SqlBound sqlBound = (SqlBound) o;
        return Objects.equals(sql, sqlBound.sql) &&
                Objects.equals(params, sqlBound.params);
    }

    @Override
    public int hashCode() {
        return Objects.hash(sql, params);
    }
}
